﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/SysIndex.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
  <script language="javascript" type="text/javascript">
      var toolbar = [
                    {
                        text: '详细',
                        iconCls: 'icon-search',
                        handler: function () {
                            crud.getView();
                        }
                    }, '-', {
                        text: '创建',
                        iconCls: 'icon-add',
                        handler: function () {
                            crud.flexiCreate();
                        }
                    }, '-', {
                        text: '删除',
                        iconCls: 'icon-remove',
                        handler: function () {
                            crud.flexiDelete();
                        }
                    }, '-', {
                        text: '修改',
                        iconCls: 'icon-edit',
                        handler: function () {
                            crud.flexiModify();
                        }
                    }, '-', {

                        text: '选择',
                        iconCls: 'icon-ok',
                        handler: function () {
                            crud.flexiSelect();
                        }
                    }];

      function Crud(controllerName) {

          this.getView = function getView() {
              var node = $('#test').treegrid('getSelected');
              if (!node) {
                  msgShow("操作提示", "请选择数据!", "info");
                  return;
              }
              var arr = new Array(0);
              arr.push(node.Id);
              if (arr.length == 1) {
                  var parent = window.dialogArguments; //获取父页面
                  if (parent != null && parent != "undefined") {//如果是父页面就不许操作
                      msgShow("操作提示", "请不要在弹出框中新建，可以转到列表中查看！", "info");
                      return;
                  }
                  window.location.href = "../" + controllerName + "/Details/" + arr[0];
                  return;
              }

          };
          this.flexiCreate = function flexiCreate() {
              var parent = window.dialogArguments; //获取父页面
              if (parent != null && parent != "undefined") {//如果是父页面就不许操作
                  msgShow("操作提示", "请不要在弹出框中新建，可以转到列表中新建！", "info");

                  return;
              }
              window.location.href = "../" + controllerName + "/Create";
              return;
          };
          this.flexiDelete = function flexiDelete() {
              var parent = window.dialogArguments; //获取父页面
              if (parent != null && parent != "undefined") {//如果是父页面就不许操作
                  msgShow("操作提示", "请不要在弹出框中删除，可以转到列表中删除！", "info");
                  return;
              }
              var node = $('#test').treegrid('getSelected');
              if (!node) {
                  msgShow("操作提示", "请选择数据!", "info");
                  return;
              }
              var arr = new Array(0);
              arr.push(node.Id);
              $.messager.confirm('删除提示', '确认删除这 1 项吗?', function (r) {
                  if (r) {
                      $.post("../" + controllerName + "/Delete", { query: arr.join(",") }, function (res) {
                          if (res == "OK") {
                              remove();
                              msgShow("操作提示", "删除成功!", "info");
                          }
                          else {
                              if (res == "") {
                                  msgShow("操作提示", "删除失败!请查看该数据与其他模块下的信息的关联，或联系管理员。", "info");
                              }
                              else {
                                  msgShow("操作提示", res, "info");
                              }
                          }
                      });
                  }
                  else
                      return;
              });
          };
          this.flexiModify = function flexiModify() {
              var node = $('#test').treegrid('getSelected');
              if (!node) {
                  msgShow("操作提示", "请选择数据!", "info");
                  // alert("请选择数据!");
                  return;
              }
              var arr = new Array(0);
              arr.push(node.Id);

              if (arr.length == 1) {
                  var parent = window.dialogArguments; //获取父页面
                  if (parent != null && parent != "undefined") {//如果是父页面就不许操作
                      msgShow("操作提示", "请不要在弹出框中新建，可以转到列表中查看！", "info");
                      return;
                  }
                  window.location.href = "../" + controllerName + "/Edit/" + arr[0];
                  return;
              }
          };
          this.flexiSelect = function flexiSelect() {
              var node = $('#test').treegrid('getSelected');
              if (!node) {
                  msgShow("操作提示", "请选择数据!", "info");

                  return;
              }
              var arr = new Array(0);
              arr.push(node.Id);
              arr.push("^"); //主键列和显示列的分割符 ^ 
              arr.push(node.Name);
              //主键列和显示列之间用 ^ 分割   每一项用 , 分割
              if (arr.length == 3) {//一条数据和多于一条
                  returnParent(arr.join("&")); //每一项用 & 分割
              }
          };
          function reload() {
              var node = $('#test').treegrid('getSelected');
              if (node) {
                  $('#test').treegrid('reload', node.code);
              } else {
                  $('#test').treegrid('reload');
              }
          };
          function remove() {
              var node = $('#test').treegrid('getSelected');
              if (node) {
                  $('#test').treegrid('remove', node.Id);
              }
          };
      }
        var ctrlName = 'SysMenu';
        var crud = new Crud(ctrlName);
         $(function () {
           using('treegrid', function () {
                $('#test').treegrid({
                    url: '../SysMenuTree/GetAllMetadata',
                    idField: 'Id',
                    treeField: 'Name',
                    rownumbers: true,
                    height: 450,
                    toolbar:toolbar,
                    frozenColumns: [[
	                    { field: 'ck', checkbox: true }
                        ,{ field: 'Name', title: '名称', width: 240 }
				    ]],
                    columns: [[
                    
					{ field: 'SysWebSiteId', title: '网站', width: 76 }
					,{ field: 'Url', title: '网址', width: 76 }
					,{ field: 'Iconic', title: '图标', width: 76 }
					,{ field: 'Sort', title: '排序', width: 76 }
					,{ field: 'State', title: '状态', width: 76 }
				    ]]
                });
          
                 var parent = window.dialogArguments; //获取父页面
                if (parent == "undefined" || parent == null) {
                    $(".l-btn.l-btn-plain:last").hide();
                } else {
                    $(".l-btn.l-btn-plain").hide();

                    $(".l-btn.l-btn-plain:last").show();
                }
            }); 
         });
      
 </script>
</asp:Content>


<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

 <table id="test">
    </table>

</asp:Content>

